package com.alibaba.otter.node.etl.load.loader.mq.rabbit.consume;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class CustomNameThreadFactory implements ThreadFactory {

    private String namePrefix;
    private static final int INIT_VAL = 0;
    private AtomicInteger index = new AtomicInteger(INIT_VAL);

    public CustomNameThreadFactory(String namePrefix) {
        this.namePrefix = namePrefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setName(namePrefix + "-" + index.getAndIncrement());
        return thread;
    }
}
